import java.io.File;
import java.io.IOException;

/**
 * @License: (C) Copyright 2013-2022
 * @Contact: abcque@outlook.com
 * @IDE: IntelliJ IDEA
 * @Encoding: utf-8
 * @Project: st2214st2215
 * @Package: PACKAGE_NAME
 * @File: FileTest.java
 * @Time: 2023/4/23 14:13
 * @Author: abcque
 * @Description:
 * @Modifier:
 * @ModifyDate:
 * @ModifyRemark:
 */
public class FileTest {
    public static void main(String[] args) {
        // 新建普通文件
        /*File file = new File("abc.txt");
        try {
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
        }*/

        // 新建一个文件夹
        /*File file = new File("directory");
        try {
            file.mkdir();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
        }*/

        // 新建层次结构的文件夹 x\y\z
        /*File file = new File("x\\y\\z");
        try {
            file.mkdirs();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
        }*/

        // 重命名 abc.txt 到 abc_backup.txt
        // File file = new File("abc.txt");
        // file.renameTo(new File("abc_backup.txt"));

        // File file = new File("abc_backup.txt");
        // file.delete();

        // File file = new File("x\\y\\z");
        // file.delete();

        // 对于非空文件夹，需要先将里面的内容删除，才能讲该文件夹删除
        // File y = new File("x\\y");
        // y.delete();
        // File x = new File("x");
        // x.delete();

        File file = new File("abc.txt");
        /*// 判断文件是否存在
        boolean exists = file.exists();
        System.out.println("exists = " + exists);

        if (exists) {
            // 判断是普通文件
            boolean b = file.isFile();
            System.out.println("文件是普通文件：" + b);
            boolean directory = file.isDirectory();
            System.out.println("文件是文件夹：" + directory);

            // 判断文件是否可读
            boolean canRead = file.canRead();
            // 判断文件是否可写入
            boolean canWrite = file.canWrite();
            System.out.println("canRead = " + canRead);
            System.out.println("canWrite = " + canWrite);

            // 判断文件是否隐藏
            boolean hidden = file.isHidden();
            System.out.println("hidden = " + hidden);
        }*/

        // 获取文件的绝对路径
        String absolutePath = file.getAbsolutePath();
        System.out.println("absolutePath = " + absolutePath);

        // 获取路径名称
        String path = file.getPath();
        System.out.println("path = " + path);
        // 获取文件名称
        String name = file.getName();
        System.out.println("name = " + name);

        String parent = file.getParent();
        System.out.println("parent = " + parent);
        // 最后一次修改时间，单位毫秒
        long lastModified = file.lastModified();
        System.out.println("lastModified = " + lastModified);

        long length = file.length();
        System.out.println("length = " + length);

        file = new File("chapter13");
        String[] list = file.list();
        for (String s : list) {
            System.out.println(s);
        }

        File[] files = file.listFiles();
        for (File file1 : files) {
            System.out.println(file1);
        }


    }
}
